﻿using System;
using UnityEngine;
using DanMuHelper.Tools;
using DanMuHelper.Logging;
using Sirenix.OdinInspector;

namespace PickMeUp
{
    public partial class GameApp : MonoBehaviourSingleton<GameApp>
    {
        public const int GameTargetFrame = 30;
        private FsmSystem<GameDefines.E_GameFSMState> _gameFsmSystem;

        [ShowInInspector]
        public GameDefines.E_GameFSMState Id
        {
            get
            {
                if (_gameFsmSystem == null)
                    return GameDefines.E_GameFSMState.InitializeState;
                return _gameFsmSystem.Id;
            }
        }

        protected override void SingletonAwake()
        {
            base.SingletonAwake();
            InitializedFsm();
        }

        private void InitializedFsm()
        {
            _gameFsmSystem = new FsmSystem<GameDefines.E_GameFSMState>();
            _gameFsmSystem.Add(new GameInitializeState(this));
            _gameFsmSystem.Add(new GameLaunchState(this));
            _gameFsmSystem.Add(new GamingState(this));
            _gameFsmSystem.Enter(GameDefines.E_GameFSMState.InitializeState);
        }

        private void Update()
        {
            _gameFsmSystem.Update(Time.deltaTime);
        }
    }
}
